<?php 		
class CSeoController extends CController{

	protected $m_arrobjSeos;
	protected $m_objSeo;
			
	function __construct() {
		parent::__construct();
		return true;
	}
	
	function create() {
		parent::create();		
	}
	
	function initialize() {
		parent::initialize();
	}
	
	function execute() {		
		
		switch( $this->m_strAction ) {
			
			case NULL:			
			case 'list':
				$this->handleViewSeoList();
				break;
											
			case 'edit':
				$this->handleEditSeo();
				break;
				
			case 'update_seo':
				$this->handleUpdateSeo();
				break;
								
			default:
				// Empty default case
				
		}
	}

	/*************************************
	********** HANDLE FUNCTIONS **********
	*************************************/
		
	function handleViewSeoList() {
		$this->m_arrobjSeos = CSeos::fetchSeos( $this->m_objDatabase );	
		$this->displaySeoList();
	}
	
	function handleEditSeo() {
		$intSeoId = $this->m_objData->getGetData( array( 'id' ) );
		if( true == isset( $intSeoId ) ) {
			$this->m_objSeo = CSeos::fetchSeoById( $intSeoId, $this->m_objDatabase );			
		}
		
		$this->displayEditSeo();
	}
	
	function handleUpdateSeo() {
		
		switch( true ) {
			default:
				$arrmixFieldsValues = $this->m_objData->getPostData( array( 'seo' ) );
		
				$this->m_objSeo = CSeos::setValues( 'CSeo', $arrmixFieldsValues );
				
				if( false == $this->m_objSeo->validate( $arrmixFieldsValues, array_keys( $arrmixFieldsValues ) ) ) {
					break;
				}
				
				if( true == isset( $arrmixFieldsValues['id'] ) ) {
				
					if( false == $this->m_objSeo->update( $this->m_objDatabase ) ) {
						$this->m_objErrorMessage->setErrorMessage( 'Failed to update seo details.' );
					} else {
						$this->m_objErrorMessage->setSuccessMessage( 'Seo details updated successfully. ' );
					}
				} 
		}
 		reload();
	}
	
	/**************************************
	********** DISPLAY FUNCTIONS **********
	**************************************/		
	
	function displaySeoList() {
		$this->display();

		$this->m_objSmarty->assign_by_ref( 'seos', $this->m_arrobjSeos );
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/admin/seo/view_seo_list.tpl');
	}
	
	function displayEditSeo() {
		$this->display();

		$this->m_objSmarty->assign_by_ref( 'seo', $this->m_objSeo );
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/admin/seo/view_edit_seo.tpl' );
	}
	
	function display() {
		
		parent::display();
		$this->m_objSmarty->assign( 'leftadminmenu', 'seomanagement' );
	}
}
?>